/*
 * VerdandiAppWindow.java
 * 
 * Copyright (c) 2008, Marshall Scorcio, Ralph Holzmann, 
 *                     Stewart Sweet, Tyler Hoersch, Jeffery Van Handel
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the University of Wisconsin Oshkosh nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.util.Vector;

public class VerdandiAppWindow extends JFrame implements ActionListener
{
    private JPanel buttonPanel;
    private JPanel statusPanel;
    
    private JButton manageEmployees;
    private JButton createSchedule;
    private JButton publishSchedule;
    
    private JLabel statusBar;
    
    private JMenuBar menuBar;
    private JMenu file;
    private JMenuItem exit;
    private JMenu help;
    private JMenuItem about;
            
    private String header = "Verdandi is an Open-Source scheduling project created to " + 
        "construct work schedules with efficiency and accuracy.\nWith a user-friendly " +
        "display, managing employee information, customizing work shifts, and scheduling " + 
        "employees\nare all simple and quick abilities. Welcome to Verdandi!\n\n" + 
        "Created By:\n-Marshall Scorcio\n-Ralph Holzmann\n-Tyler Hoersch\n-Stewart Sweet\n-Jeffery Van Handel\n\n" +
        "If you want to contribute to Verdandi, you can visit our project home at:\n" +
        "<html><a href='http://code.google.com/p/verdandi'>code.google.com/p/verdandi</a></html>";
    
    private Vector<Employee> employees;
    private Schedule schedule;
    
    public VerdandiAppWindow()
    {
        super("Verdandi");
        setSize(400, 250);
        setLocation(300, 300);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE); 
              
        employees = new Vector<Employee>();
        employees = EmployeeSerializer.loadEmployees();
        schedule = ScheduleSerializer.loadSchedule();
        
        initComponents();
    }
    
    public void initComponents()
    {        
        statusBar = new JLabel("<html><font color=gray>Status: " + EmployeeSerializer.getStatus() + " " + ScheduleSerializer.getStatus() + "</font></html>");
        statusBar.setSize(100, 16);
     
        statusPanel = new JPanel(new BorderLayout());
        statusPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        statusPanel.add(statusBar, BorderLayout.PAGE_START);
        
        menuBar = new JMenuBar();
        file = new JMenu("File");
        help = new JMenu("Help");
        exit = new JMenuItem("Exit");
        about = new JMenuItem("About");
        
        file.add(exit);
        help.add(about);
        menuBar.add(file);
        menuBar.add(help);        
        
        manageEmployees = new JButton("Step 1: Manage Employees");
        createSchedule = new JButton("Step 2: Create Schedule");
        publishSchedule = new JButton("Step 3: Publish Schedule");
        
        GridLayout layout = new GridLayout(3, 0);
        layout.setVgap(7);
        
        buttonPanel = new JPanel(layout);
        buttonPanel.add(manageEmployees);
        buttonPanel.add(createSchedule);
        buttonPanel.add(publishSchedule);
        
        manageEmployees.addActionListener(this);
        createSchedule.addActionListener(this);
        publishSchedule.addActionListener(this);
        exit.addActionListener(this);
        about.addActionListener(this);
        
        add(menuBar, BorderLayout.NORTH);
        add(buttonPanel, BorderLayout.CENTER);
        add(statusPanel, BorderLayout.SOUTH);
    }
    
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource().equals(manageEmployees))
        {
            new EmployeeWindowController().setEmployees(employees);
        }
        else if (e.getSource().equals(createSchedule))
        {
            ScheduleCreationWindowController scheduleCreationWindowController = new ScheduleCreationWindowController();
            scheduleCreationWindowController.setEmployees(employees);
            scheduleCreationWindowController.setSchedule(schedule);
        }
        else if (e.getSource().equals(publishSchedule))
        {
            PublishScheduleWindowController publishController = new PublishScheduleWindowController(schedule);
            publishController.setEmployees(employees);
        }
        else if (e.getSource().equals(about))
        {
            JOptionPane.showMessageDialog(null, header, "About Verdandi", JOptionPane.PLAIN_MESSAGE);
        }
        else if (e.getSource().equals(exit))
        {
            System.exit(0);
        }
   }
    
}
